<template>
	<view class="content">

		<view class="user-image">
			<image src="../../static/login/logo@2x.png" mode=""></image>
		</view>
		<view class="login">
			<u-button v-if="value==''" :custom-style="customStyle"  type="primary" size="medium"  @click="validatePhone">授权手机号快捷登录</u-button>
			<u-button v-else :custom-style="customStyle"  type="primary" size="medium" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权手机号快捷登录</u-button>
			<!-- <button >手机号</button> -->
		</view>
		<view class="treaty">

			<u-radio-group v-model="value" @change="radioGroupChange">
				<u-radio @change='boxcheck' active-color="#1677FE" name='checked'>

				</u-radio>
			</u-radio-group>
			<view class="userService">
				我已阅读同意<text>用户协议</text>和<text>隐私协议</text>
			</view>
		</view>
		<!-- 勾选提示框 -->
		<view class="empower">
			请先勾选同意授权协议
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '../../common/api.js'
	export default {
		data() {
			return {
				customStyle: {
					backgroundColor: "#1677FE",
					height: '95rpx',
					padding: '0 130rpx',
					fontSize: "30rpx",
					width: '100%'
				},
				state: false, //预先未勾选的状态,
				value: ''
			}
		},
		onLoad() {

		},
		methods: {
			// getPhoneNumber(e) {
			// 	console.log(e)
			// },
			boxcheck(e) {
				// console.log(e)
				// this.state = !this.state;
			},
			getPhone(e){
				console.log(e)
			},
			radioGroupChange(e) {
				console.log(this.value)
				
			},
			validatePhone(){
				if (this.value == '') {
					// 未勾选提示
					uni.$u.toast('请先勾选同意授权协议')
					return 
				}
			},
			getPhoneNumber(e) {
				console.log(e,'eeee')
				let _this = this;
				if (this.value == '') {
					// 未勾选提示
					uni.$u.toast('请先勾选同意授权协议')
					return 
				} else {
					// wx.setStorageSync('user_info', user.userInfo);
					wx.login({
						success(response) {
						
							let data = {
								code: response.code,
								encryptedData: e.detail.encryptedData,
								userHeadPic: '',
								iv: e.detail.iv
							}
							_this.$Api.login(data).then(res => {
								
								uni.setStorageSync('userInfo',res.data.sysUser)
								// 获取用户信息
								uni.request({
									url:"https://s6986h7373.yicp.fun:443/api/sp/user/getUserInfo",
									method:"GET",
									header:{
										"content-type":"application/x-www-form-urlencoded"
									},
									data:{
										openid:res.data.sysUser.openid,
										
									},
									success(xhr){
										console.log(xhr)
									}
								})
								// _this.$Api.getUserInfoByOpenId({}).then(info=>{
								// 	console.log(info)
								// })
								// uni.show
								uni.switchTab({
									url:"../index/index"
								})
							})
							// uni.request({
							// 	url:'http://119.96.191.80:4097/api/sp/user/doRegister',
							// 	method:"POST",
							// 	data,
							// 	header:{
							// 		'conten-type':"application/x-www-form-urlencoded"
							// 	},
							// 	success(res) {
							// 		console.log(res)
							// 	}
							// })
						}
					})
					// wx.getUserProfile ({
					// 	desc:"用于完善用户资料",
					// 	success(user) {
					// 		console.log(user)
							
					// 	}
					// })
					// 已勾选继续授权完成登录
				
				}
			},
			test() {
				uni.navigateTo({
					url: "/pagesA/mall/index"
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "index.scss"
</style>